package com.shoe.controller;

import com.shoe.service.AdminAftersaleService;
import com.shoe.util.ResultUtil;
import com.shoe.vo.AdminAftersaleVo;
import com.shoe.vo.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("admin")
public class AdminAftersaleController {

    @Autowired
    AdminAftersaleService adminAftersaleService;

    @Autowired
    ResultUtil resultUtil;

    @GetMapping("sellayall")
    public ResponseResult selLayAll(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer limit) {

        List<AdminAftersaleVo> seLuiAaftAll = adminAftersaleService.seLuiAaftAll();
        List<AdminAftersaleVo> seLuiAaftPage = adminAftersaleService.seLuiAaftPage((page - 1) * limit, limit);

        if (null != seLuiAaftPage && seLuiAaftPage.size() > 0) {
            return resultUtil.getResponseResult(0, "", seLuiAaftAll.size(), seLuiAaftPage);
        } else {
            return resultUtil.getResponseResult(2, "查询失败");
        }
    }

    @GetMapping("selectadminaftersale")
    public ResponseResult selectAdminAftersaleByAftsaleId(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer limit, String aftsaleSolve, String key) {

        List<AdminAftersaleVo> adminAftersaleVoListPage = adminAftersaleService.selectAdminAftersaleByAftsaleIdPag((page - 1) * limit, limit, aftsaleSolve);
        List<AdminAftersaleVo> adminAftersaleVoListAll = adminAftersaleService.selectAdminAftersaleByAftsaleId(aftsaleSolve);

        if (null != adminAftersaleVoListPage && adminAftersaleVoListPage.size() > 0) {
            return resultUtil.getResponseResult(0, "", adminAftersaleVoListAll.size(), adminAftersaleVoListPage);
        } else {
            return resultUtil.getResponseResult(2, "查询失败");
        }

    }

    @GetMapping("updataAdminAftersale")
    public ResponseResult updataAdminAftersale(Integer aftSaleId, String aftSaleState, String aftSaleReq) {

        int affrow = adminAftersaleService.updataAdminAftersale(aftSaleId, aftSaleState, aftSaleReq);
        if (affrow > 0) {
            return resultUtil.getResponseResult(0, "");
        } else {
            return resultUtil.getResponseResult(2, "更改失败");
        }
    }

    @GetMapping("deleteAdminAftersale")
    public ResponseResult delAAftersaleByAftSaleId(Integer aftSaleId) {
        int affRow = adminAftersaleService.deleteAdminAftersale(aftSaleId);
        if (affRow > 0) {
            return resultUtil.getResponseResult(0, "");
        } else {
            return resultUtil.getResponseResult(2, "删除成功");
        }
    }
}
